<?php

namespace App\Admin\Controllers;

use App\Models\sgbdb;
use Encore\Admin\Form;
use Encore\Admin\Http\Controllers\AdminController;
use Encore\Admin\Show;
use Encore\Admin\Table;


class SgbController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = 'sgbdb';

    /**
     * Make a table builder.
     *
     * @return Table
     */
    protected function table()
    {




        /**
         * [$shijiIndexMap description]
         * 诗集名称的映射
         * @var [type]
         */
        $shijiIndexMap = [
            '0'=>'附录',
             '1'=>'赞美耶稣诗集',
              '2'=>'新编赞美诗',
               '3'=>'少儿赞美',
        ];


        $table = new Table(new sgbdb());


        $table->header(function ($query) {
            return 'header';
        });

        $table->footer(function ($query) {
            return 'footer'; 
        });

        $table->quickSearch();

        $table->filter(function($filter){

            $shijiIndexMap = [
            '0'=>'附录',
             '1'=>'赞美耶稣诗集',
              '2'=>'新编赞美诗',
               '3'=>'少儿赞美',
            ];


            // 去掉默认的id过滤器
            $filter->disableIdFilter();

            // 在这里添加字段过滤器
            $filter->in('shijiIndex', '所属诗集')->select($shijiIndexMap);


            $filter->like('Mulu','标题');
            

        });



        $table->column('mulu', __('Mulu'))->text();
        $table->column('shijiIndex', __('ShijiIndex'))->using($shijiIndexMap)->sortable();;
        $table->column('xuhao', __('Xuhao'))->sortable();;


        $table->column('_id', __(' id'))->hide();
        $table->column('isad', __('Isad'))->bool(['1' => true, '0' => false]);
        $table->column('isopern', __('Isopern'))->bool(['1' => true, '0' => false]);
        $table->column('lyrice', __('Lyrice'))->width(200)->limit(10);;
        
        return $table;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(sgbdb::findOrFail($id));

        $show->field('_id', __(' id'));
        $show->field('isad', __('Isad'));
        $show->field('isopern', __('Isopern'));
        $show->field('lyrice', __('Lyrice'));
        $show->field('mulu', __('Mulu'));
        $show->field('shijiIndex', __('ShijiIndex'));
        $show->field('xuhao', __('Xuhao'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new sgbdb());

        $form->number('isad', __('Isad'));
        $form->number('isopern', __('Isopern'));
        $form->textarea('lyrice', __('Lyrice'));
        $form->text('mulu', __('Mulu'));
        $form->number('shijiIndex', __('ShijiIndex'));
        $form->number('xuhao', __('Xuhao'));

        return $form;
    }
}
